package com.kejizhentan.springboot2thymeleaf.exception;

import lombok.SneakyThrows;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Order(value = Ordered.HIGHEST_PRECEDENCE)//提高自定义异常处理器的优先级，value值越小，优先级越高
@Component
public class KejizhentanHandlerExceptionResolver implements HandlerExceptionResolver {
    @SneakyThrows
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        httpServletResponse.sendError(511,"我自己喜欢的错误");
        return new ModelAndView();
    }
}
